﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace StockVentas
{
    public partial class frmArqueoInter : Form
    {
        DataTable tblLocales;
        DataTable tblPc;
        DataView viewLocales;
        DataView viewPc;
        string strFilePath;

        public frmArqueoInter()
        {
            InitializeComponent();
        }

        private void frmArqueoInter_Load(object sender, EventArgs e)
        {
            strFilePath = Application.StartupPath + "\\Datasets_xml\\";
            if (File.Exists(strFilePath + "Locales.xml"))
            {
                tblLocales = new DataTable();
                tblLocales.ReadXml(strFilePath + "Locales.xml");
                tblLocales.AcceptChanges();
            }
            viewLocales = new DataView(tblLocales);
            viewLocales.RowFilter = "IdLocalLOC ='13'"; // Local 13 es Jesus Maria
            lstLocales.ValueMember = "IdLocalLOC";
            lstLocales.DisplayMember = "NombreLOC";
            lstLocales.DataSource = viewLocales;
            if (File.Exists(strFilePath + "Pc.xml"))
            {
                tblPc = new DataTable();
                tblPc.ReadXml(strFilePath + "Pc.xml");
                tblPc.AcceptChanges();
            }
            viewPc = new DataView(tblPc);
            viewPc.RowFilter = "IdPC = '1'"; // Pc 1 es caja1 de Jesus Maria
            lstPc.ValueMember = "IdPC";
            lstPc.DisplayMember = "Detalle";
            lstPc.DataSource = viewPc;
            this.lstLocales.SelectedValueChanged += new System.EventHandler(this.lstLocales_SelectedValueChanged);
            dateTimePicker1.Enabled = false;
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            frmArqueoCajaAdmin arqueo = new frmArqueoCajaAdmin();
            arqueo.fechaDesde = dateTimePicker1.Value;
            arqueo.fechaHasta = dateTimePicker1.Value;
            arqueo.idLocal = Convert.ToInt32(lstLocales.SelectedValue.ToString());
            arqueo.nombreLocal = lstLocales.Text;
            arqueo.idPc = Convert.ToInt32(lstPc.SelectedValue.ToString());
            arqueo.Show();
        }

        private void lstLocales_SelectedValueChanged(object sender, EventArgs e)
        {
            string local = lstLocales.SelectedValue.ToString();
            viewPc = new DataView(tblPc);
            viewPc.RowFilter = "IdLocalPC = '" + local + "'";
            viewPc.Sort = "Detalle ASC";
            lstPc.ValueMember = "IdPC";
            lstPc.DisplayMember = "Detalle";
            lstPc.DataSource = viewPc;
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}
